#ifndef __LISTABLOQUEANTE_H__
#define __LISTABLOQUEANTE_H__

#include <list>
#include "Mutex.h"
#include "Lock.h"

template <typename T>
class ListaBloqueante {
  std::list<T> list;
  Mutex m;
  Lock * myLock;
	public:

		ListaBloqueante (){};

		void push_back (const T &i){
			Lock l(m);
			list.push_back(i);
		};

		void pop_back (){
			Lock l(m);
			list.pop_back();
		};

		void push_front (const T &i){
			Lock l(m);
			list.push_front(i);
		};

		void pop_front (){
			Lock l(m);
			list.pop_front();
		};

		T& front (){
			Lock l(m);
			return list.front();
		};

		T& back (){
			Lock l(m);
			return list.back();
		};

		size_t size (){
			Lock l(m);
			return list.size();
		};

		void lock(){
			myLock = new Lock(m);
		}

		typename std::list<T>::iterator begin(){
			return list.begin();
		}

		typename std::list<T>::iterator end(){
			return list.end();
		}

		typename std::list<T>::iterator erase (typename std::list<T>::iterator position){
			return list.erase(position);
		}

		void unlock(){
			delete(myLock);
		}

};

#endif
